class Solution {
public:
    bool isprime(int n)
    {
        if (n == 1) return false;
        if (n > 1)
        {
            for (int i = 2; i <= sqrt(n); i++)
            {
                if (n % i == 0)
                    return false;
            }
        }
        return true;
    }

    int diagonalPrime(vector<vector<int>>& nums)
    {
        int n = nums.size();
        int ans = 0;
        for (int i = 0; i < n; i++) if (isprime(nums[i][i])) ans = max(ans, nums[i][i]);
        for (int i = 0, j = n - 1; i < n, j >= 0; i++, j--) if (isprime(nums[i][j])) ans = max(ans, nums[i][j]);
        return ans;
    }
};